package com.yungam.other.service.impl;

import com.yungam.common.utils.HttpUtils;
import com.yungam.other.service.MesService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.HttpMethod;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Slf4j
@Service
@ConfigurationProperties(prefix = "mes")
public class MesServiceImpl implements MesService {

    private String urlPrefix;
    private final HttpUtils httpUtils;

    @Autowired
    public MesServiceImpl(HttpUtils httpUtils) {
        this.httpUtils = httpUtils;
    }

    public void setUrlPrefix(String urlPrefix) {
        this.urlPrefix = urlPrefix;
    }

    public String getUrlPrefix() {
        return this.urlPrefix;
    }

    @Override
    public Map<String, Object> passStation(Map<String, Object> passData) {
        String url = this.urlPrefix + "/passStation";
        return httpUtils.httpExchange(url, HttpMethod.POST, passData);
    }

    @Override
    public Map<String, Object> preprocess(Map<String, Object> preprocessRecord) {
        String url = this.urlPrefix + "/preprocess";
        return httpUtils.httpExchange(url, HttpMethod.POST, preprocessRecord);
    }

    @Override
    public Map<String, Object> addCollectData(List<Map<String, Object>> collectData) {
        String url = this.urlPrefix + "/addCollectData";
        return httpUtils.httpExchange(url, HttpMethod.POST, collectData);
    }

    @Override
    public Map<String, Object> addException(Map<String, Object> exceptionData) {
        String url = this.urlPrefix + "/addException";
        return httpUtils.httpExchange(url, HttpMethod.POST, exceptionData);
    }

}
